@import "./toggle";
@import "./toggle.md.vars";

// Material Design Toggle
// -----------------------------------------

:host {
  --background: #{$toggle-md-track-background-color-off};
  --background-checked: #{ion-color(primary, base, $toggle-md-track-background-color-alpha-on)};
  --handle-background: #{$toggle-md-handle-background-color-off};
  --handle-background-checked: #{ion-color(primary, base)};

  @include padding($toggle-md-padding-top, $toggle-md-padding-end, $toggle-md-padding-bottom, $toggle-md-padding-start);

  box-sizing: content-box;

  position: relative;

  width: $toggle-md-track-width;
  height: $toggle-md-track-height;

  contain: strict;
}

:host(.ion-color.toggle-checked) .toggle-icon {
  background: current-color(base, $toggle-md-track-background-color-alpha-on);
}

:host(.ion-color.toggle-checked) .toggle-inner {
  background: current-color(base);
}

// Material Design Toggle Background Track: Unchecked
// -----------------------------------------

.toggle-icon {
  @include border-radius($toggle-md-track-height);

  display: block;
  position: relative;

  width: 100%;
  height: 100%;

  transition: background-color $toggle-md-transition-duration;

  background: var(--background);
  pointer-events: none;
}


// Material Design Toggle Inner Knob: Unchecked
// -----------------------------------------

.toggle-inner {
  @include position(($toggle-md-handle-height - $toggle-md-track-height) / -2, null, null, 0);
  @include border-radius($toggle-md-handle-border-radius);

  position: absolute;

  width: $toggle-md-handle-width;
  height: $toggle-md-handle-height;

  transition-duration: $toggle-md-transition-duration;
  transition-property: transform, background-color;
  transition-timing-function: cubic-bezier(0.4, 0.0, 0.2, 1);

  background: var(--handle-background);

  box-shadow: $toggle-md-handle-box-shadow;
  will-change: transform, background-color;
  contain: strict;
}


// Material Design Toggle Background Track: Checked
// -----------------------------------------

:host(.toggle-checked) .toggle-icon {
  background: var(--background-checked);
}

// Material Design Toggle Inner Knob: Checked
// -----------------------------------------

:host(.toggle-checked) .toggle-inner {
  @include transform(translate3d($toggle-md-track-width - $toggle-md-handle-width, 0, 0));

  background: var(--handle-background-checked);
}


// Material Design Toggle: Disabled
// -----------------------------------------

:host(.toggle-disabled) {
  opacity: $toggle-md-disabled-opacity;
}


// TODO: move to item
// .item-md.item-toggle-disabled ion-label {
//   opacity: $toggle-md-disabled-opacity;

//   pointer-events: none;
// }

// .toggle-md.toggle-disabled ion-radio {
//   opacity: $toggle-md-disabled-opacity;
// }


// Material Design Toggle Within An Item
// -----------------------------------------

:host(.in-item[slot]) {
  @include margin($toggle-md-media-margin-top, $toggle-md-media-margin-end, $toggle-md-media-margin-bottom, $toggle-md-media-margin-start);
  @include padding($toggle-md-item-end-padding-top, $toggle-md-item-end-padding-end, $toggle-md-item-end-padding-bottom, $toggle-md-item-end-padding-start);

  cursor: pointer;
}

:host(.in-item[slot="start"]) {
  @include padding($toggle-md-item-start-padding-top, $toggle-md-item-start-padding-end, $toggle-md-item-start-padding-bottom, $toggle-md-item-start-padding-start);
}
